package com.sunny.ynhz.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.sunny.ynhz.event.MyEvenBus;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Administrator on 2017/7/17/017.
 */

public class IntentBrocast extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectivityManager
                = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mobNetInfo
                = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        NetworkInfo wifiNetInfo
                = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
            EventBus.getDefault().post(new MyEvenBus(0));
        } else {
            EventBus.getDefault().post(new MyEvenBus(1));
        }
    }
}
